package com.linkhub.oms.admin.modules.track.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckRole;
import cn.dev33.satoken.annotation.SaMode;
import com.linkhub.oms.admin.modules.track.domain.param.OrderTrackQueryParam;
import com.linkhub.oms.admin.modules.order.domain.vo.OrderTabCountVO;
import com.linkhub.oms.admin.modules.track.domain.vo.OrderTrackListVo;
import com.linkhub.oms.admin.modules.track.service.OrderTrackBizService;
import com.linkhub.oms.admin.modules.satoken.session.LhSessionContext;
import com.linkhub.oms.common.constant.RoleConstant;
import com.linkhub.oms.common.response.DataResponse;
import com.linkhub.oms.common.response.PageDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @author Redball
 * @version 1.0.0
 * @Description OrderTrackController
 * @createTime 2024/10/20 下午2:36
 */
@Slf4j
@RestController
@Api(tags = {"订单追踪接口模块"})
@RequestMapping("/order/track/")
@SaCheckLogin
@SaCheckRole(value = {RoleConstant.CUSTOMER, RoleConstant.EMPLOYEE}, mode = SaMode.OR)
public class OrderTrackController {

    @Resource
    private OrderTrackBizService orderTrackBizService;

    @GetMapping("/list")
    @ApiOperation(value = "订单追踪列表查询接口")
    public DataResponse<PageDTO<OrderTrackListVo>> pageCustomerOrders(@Validated OrderTrackQueryParam orderQueryParam) {
        // 如果用户是商家，只返回当前商家所有商店的追踪订单；如果是员工，则返回所有商家的追踪订单
        if(LhSessionContext.isCustomerRole()) {
            orderQueryParam.setSysShopIds(LhSessionContext.getUserShopIds());
        }
        return DataResponse.success(orderTrackBizService.pageOrders(orderQueryParam));
    }

    @GetMapping("/tab/count")
    @ApiOperation(value = "订单追踪页签数量接口")
    public DataResponse<List<OrderTabCountVO>> getTabOrderCount() {
        // 如果用户是商家，只返回当前商家所有商店的追踪订单各页签数；如果是员工，则返回所有商家的追踪订单各页签数

        return DataResponse.success(orderTrackBizService.getTabCount());
    }

    @GetMapping("/export")
    @ApiOperation(value = "运单追踪导出接口")
    public void trackExportExcel( @RequestParam(value = "sysShopIds", required = false) List<String> sysShopIds, HttpServletResponse response ) {
        orderTrackBizService.trackExportExcel(sysShopIds, response);
    }
}
